package com.Factory;

import com.Result.GroupApplyResult;
import com.entity.Group;
import com.entity.GroupApply;
import com.entity.User;
import com.mapper.GroupMapper;
import com.mapper.UserMapper;
import com.service.GroupApplyService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class GroupApplyResultFactory {
    @Autowired
    private UserMapper userMapper;

    @Autowired
    private GroupMapper groupMapper;

    public GroupApplyResult newGroupApplyResult(GroupApply groupApply) {
        User user = this.userMapper.selectById(groupApply.getUserId());
        Group group = this.groupMapper.selectById(groupApply.getGroupId());
        GroupApplyResult groupApplyResult = new GroupApplyResult();
        BeanUtils.copyProperties(groupApply, groupApplyResult);
        groupApplyResult.setGroupName(group.getName());
        groupApplyResult.setUserName(user.getName());
        switch(groupApply.getStatus()) {
            case(0):
                groupApplyResult.setStatus("待处理");
                break;
            case(1):
                groupApplyResult.setStatus("已同意");
                break;
            case(2):
                groupApplyResult.setStatus("已拒绝");
                break;
            case(3):
                groupApplyResult.setStatus("已失效");
                break;
        }
        return groupApplyResult;
    }
}
